<!DOCTYPE html>
<html lang="en">
	<head>
		<title>three.js webgl - loaders - vtk loader</title>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
		<style>
			body {
				font-family: Monospace;
				background-color: #000;
				color: #fff;
				margin: 0px;
				overflow: hidden;
			}
			#info {
				color: #fff;
				position: absolute;
				top: 10px;
				width: 100%;
				text-align: center;
				z-index: 100;
				display:block;
			}
			#info a, .button { color: #f00; font-weight: bold; text-decoration: underline; cursor: pointer }
		</style>
	</head>

	<body>
		<script src='javascript/inflate.min.js'></script>
		<script src="javascript/three.js"></script>
		<script src="javascript/TrackballControls.js"></script>
		<script src="javascript/VTKLoader.js"></script>
		<script src="javascript/Detector.js"></script>
		<script src="javascript/stats.min.js"></script>
		<script>
			if ( ! Detector.webgl ) Detector.addGetWebGLMessage();

			var container;

			var camera, controls, scene, renderer;

			var cross;

			init();
			animate();

			function init() {

				camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 0.01, 1e10 );
				camera.position.z = 0.2;

				controls = new THREE.TrackballControls( camera );

				controls.rotateSpeed = 5.0;
				controls.zoomSpeed = 5;
				controls.panSpeed = 2;

				controls.noZoom = false;
				controls.noPan = false;

				controls.staticMoving = true;
				controls.dynamicDampingFactor = 0.3;

				scene = new THREE.Scene();

				scene.add( camera );

				// light

				var dirLight = new THREE.DirectionalLight( 0xffffff );
				dirLight.position.set( 200, 200, 1000 ).normalize();

				camera.add( dirLight );
				camera.add( dirLight.target );

				var material = new THREE.MeshLambertMaterial( { color: 0xffffff, side: THREE.DoubleSide } );

				var loader = new THREE.VTKLoader();
				loader.load( "images/vtk/bunny.vtk", function ( geometry ) {
				geometry.center();
				geometry.computeVertexNormals();
				var mesh = new THREE.Mesh( geometry, material );
				mesh.position.set( - 0.075, 0.005, 0 );
				mesh.scale.multiplyScalar( 0.2 );
				scene.add( mesh );
				} );

				var loader1 = new THREE.VTKLoader();
				loader1.load( 'images/vtk/cube_ascii.vtp', function ( geometry ) {

					geometry.computeVertexNormals();
					geometry.center();

					var material = new THREE.MeshLambertMaterial( { color: 0x00ff00, side: THREE.DoubleSide } );
					var mesh = new THREE.Mesh( geometry, material );

					mesh.position.set( - 0.025, 0, 0 );
					mesh.scale.multiplyScalar( 0.01 );


					scene.add( mesh );

				} );

				var loader2 = new THREE.VTKLoader();
				loader2.load( 'images/vtk/cube_binary.vtp', function ( geometry ) {

					geometry.computeVertexNormals();
					geometry.center();

					var material = new THREE.MeshLambertMaterial( { color: 0x0000ff, side: THREE.DoubleSide } );
					var mesh = new THREE.Mesh( geometry, material );

					mesh.position.set( 0.025, 0, 0 );
					mesh.scale.multiplyScalar( 0.01 );


					scene.add( mesh );

				} );

				var loader3 = new THREE.VTKLoader();
				loader3.load( 'images/vtk/cube_no_compression.vtp', function ( geometry ) {

					geometry.computeVertexNormals();
					geometry.center();

					var material = new THREE.MeshLambertMaterial( { color: 0xff0000, side: THREE.DoubleSide } );
					var mesh = new THREE.Mesh( geometry, material );

					mesh.position.set( 0.075, 0, 0 );
					mesh.scale.multiplyScalar( 0.01 );


					scene.add( mesh );

				} );

				// renderer
				renderer = new THREE.WebGLRenderer( { antialias: false } );
				renderer.setPixelRatio( window.devicePixelRatio );
				renderer.setSize( window.innerWidth, window.innerHeight );
				container = document.createElement( 'div' );
				document.body.appendChild( container );
				container.appendChild( renderer.domElement );

			}

			function animate() {
			  requestAnimationFrame( animate );
		      controls.update();
			  renderer.render( scene, camera );
			}

		</script>

	</body>
</html>
